package com.mall.search.web.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.mall.pojo.SearchResult;
import com.mall.search.service.SearchItemService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author Administrator
 */
@Controller
public class SearchController {

    @Reference
    SearchItemService searchItemService;

    @Value("${rows}")
    private int rows;

    @GetMapping("/search")
    public String Search(String keyword, Model model, @RequestParam(value = "page",defaultValue = "0") int page){
        SearchResult searchResult = searchItemService.SearchItems(keyword,page,rows);
        model.addAttribute("recordCount",searchResult.getRecordCount());
        model.addAttribute("totalPages",searchResult.getTotalPages());
        model.addAttribute("itemList",searchResult.getItemList());
        return "search";
    }
}
